package com.bc.util;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.bc.datasource.vo.SendObject;

public class FetchAsiaUtil {

	static String url = "http://vip.win007.com/AsianOdds_n.aspx?id=";
	
	public static void setYa(SendObject so){
		
		String url1 = url + so.getId();
		try {
			Document doc = Jsoup.connect(url1).header("Host", "live.titan007.com")
					  .header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36 QQBrowser/3.9.3952.400")
					  .get();
			Element table = doc.getElementById("odds");
			if(table==null)return;
			Elements trs = table.getElementsByTag("tr");
			String odd1 ="";
			String pan1="";
			String odd2 ="";
			for (int i = 2; i<trs.size()&&i<3;i++) {
				Element e = trs.get(i);
				Elements tds = e.getElementsByTag("td");
				if(tds.get(0).text().length()>0){
					odd1 = tds.get(2).text();
					pan1 = tds.get(3).text();
					odd2 = tds.get(4).text();
					Elements tds1 = e.getElementsByAttributeValue("oddsType", "wholeOdds");
					String odd3 = tds1.get(0).text();
					String pan2 = tds1.get(1).text();
					String odd4 = tds1.get(2).text();
					// ya odds to object
					so.setYaHome1(odd1);
					so.setYaHome2(odd2);
					so.setYaVisit1(odd3);
					so.setYaVisit2(odd4);
					
					//ya pan to object
					so.setPankou(pan2);
					so.setPan0(pan1);
					
				}
				so.setFanz(false);
				so.setPro("");
			}
			Thread.sleep(200);
		} catch (Exception e) {
			try {
				Thread.sleep(1200);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
	}
}
